package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.*;
import javafx.util.Pair;

import java.util.*;

public class BankApplication {

    public static void main(String[] args) {
        List<Client> bankClients = generateClients(5);

        BankService service = new BankService();
        Bank bank = new Bank();
        for (Client c : bankClients) {
            service.addClient(bank, c);
        }

        service.printBalance(bank);
        service.printMaximumAmountToWithdraw(bank);
        modifyBank(bank);
        service.printBalance(bank);
        service.printMaximumAmountToWithdraw(bank);
    }

    static List<Client> generateClients(int num) {
        assert(num > 0);
        String[] names = {"Gerrard", "Rooney", "Terry", "Lampard"};

        List<Client> result = new ArrayList<Client>();
        for (int i = 0; i < num; i++) {
            Client client;
            if (i < names.length) {
                client = new Client(names[i], Gender.MALE);
            } else {
                client = new Client();
            }
            Account newAcc;
            if (Math.random() < 0.5) {
                newAcc = new CheckingAccount(Math.random() * 100, Math.random() * 1000);
            } else {
                newAcc = new SavingAccount(Math.random() * 500);
            }
            client.addAccount(newAcc);
            result.add(client);
        }
        return result;
    }

    static void modifyBank(Bank bank) {
        for (Client c : bank.getClients()) {
            Account acc = c.getAccounts().get(0);
            if (Math.random() < 0.5) {
                double amount = Math.random() * 100;
                if (Math.random() < 0.5) {
                    acc.deposit(amount);
                } else if (acc.maximumAmountToWithdraw() >= amount) {
                    acc.withdraw(amount);
                }
            }
        }
    }
}